<?php if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8">
<div class="main-content" id="main-content">
		<div class="sub-content">
			<div class="top-header page-header clearfix">
				<h1>Admin Profile</h1>
			</div>
			<div class="top-links">
				<ul>
					<? if(isset($_GET['edit']) && $_GET['edit']!=""){?>
						<li class="active-menu"><a href="<? echo $this->Url('users')?>/addadmin?user_id=<? echo $_GET['user_id'];?>&edit=1"><span>1</span></a></li>
						<li><span>2</span></li>
						<li><span>3</span></li>
					<?}else if(isset($_GET['user_id']) && $_GET['user_id']!=""){?>
						<li><a href="<? echo $this->Url('users')?>/addadmin?user_id=<? echo $_GET['user_id'];?>"><span>1</span></a></li>
						<li><span>2</span></li>
						<li><span>3</span></li>
					<?}else{?>
						<li class="active-menu"><a href="<? echo $this->Url('users')?>/addadmin"><span>1</span></a></li>
						<li><span>2</span></li>
						<li><span>3</span></li>
					<?}?>	
				</ul>
			</div>
		<div class="middle-forms user-profile1 col-md-11">
				<form id="signupForm" name="signupForm"  method="post" class="form-horizontal" role="form">
						<div class="form-group">
							<label class="control-label col-sm-3 ">Company Name</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['cname'])){?>
								<input  type="text" id="cname" name="cname" class="form-control"  value="<? echo $_SESSION['usersinfo']['cname'];?>" placeholder="Company Name"> 
							<?}else if(isset($this->user_details->company_name)){?>
							<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
								<input  type="text" id="cname" name="cname" class="form-control" value="<? echo $this->user_details->company_name;?>" placeholder="Company Name"> 
							<?}else{?>
								<input  type="text" id="cname" name="cname"  readonly="readonly" class="form-control" value="<? echo $this->user_details->company_name;?>" placeholder="Company Name"> 
							<?}}else{?>
							<input  type="text" id="cname" name="cname" value="" class="form-control" placeholder="Company Name"> 
							<?}?></div>
						</div><span style="color:red" id="errorcname"></span>
						<div id="indsCtrs">
							<div class="form-group" id="currCFormsList1">
								<label class="control-label col-sm-3 ">Country</label>
								<div class="col-sm-9">
								<? if(isset($this->user_details->country) && $this->user_details->country!=""){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<div class="select_6">
										<select id="country1" name="country[]" class="form-control">
											<option value="">-Select a country</option>	
											<?php if(isset($this->countries) && count($this->countries)>0){foreach($this->countries as $countries){										
											if($_SESSION['usersinfo']['country']==$countries->country_id){?>
											  <option value="<? echo $countries->country_id.'-'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option>
											<?}else if($this->user_details->country==$countries->country_id){?>
												<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option> 
											<?}else{?>
												<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>"><? echo $countries->nicename;?></option> 
											<?}}}?>	
										</select>
									</div>&nbsp;<a  style='cursor:hand;cursor:pointer' id='curAddC' Onclick="Javascript:addCountry();"><u>Add</u></a><a id='curDelC'></a>
								<?}else{?>
									<input type="text" readonly="readonly" value="<? echo $this->user_details->usercountry;?>" class="form-control">
									<input type="hidden" id="country" name="country" value="<? echo $this->user_details->country;?>">
								<?}}else{?>
									<div class="select_6">
										<select id="country1" name="country[]"  readonly="readonly" class="form-control">
											<option value="">-Select a country</option>	
											<?php if(isset($this->countries) && count($this->countries)>0){foreach($this->countries as $countries){										
											if(isset($_SESSION['usersinfo']['country']) && $_SESSION['usersinfo']['country']==$countries->country_id){?>
												<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option> 
											<?}else{?>
												<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>"><? echo $countries->nicename;?></option> 
											<?}}}?>	
										</select>
									</div>&nbsp;<a  style='cursor:hand;cursor:pointer' id='curAddC' Onclick="Javascript:addCountry();"><u>Add</u></a><a id='curDelC'></a>
								<?}?></div>
							</div><span id="errorcountry1" style='color:red';></span>
							<div class="form-group" id="currFormsList1">
								<label class="control-label col-sm-3 ">Industry</label>
								<div class="select_6 col-sm-9">
									<select id="industry1" name="industry[]" class="form-control">
										<option value="">-Select a industry</option>	
									</select>
								</div>
							</div><span style="color:red" id="errorindustry1"></span>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-3 ">Address 1</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['address1'])){?>
								<textarea  class="profile_add form-control" id="address1" name="address1" ><? echo $_SESSION['usersinfo']['address1'];?></textarea>
							<? } else if(isset($this->user_details->address1)){
								if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<textarea  class="profile_add form-control" id="address1"  name="address1" ><? echo $this->user_details->address1;?></textarea>
								<?}else{?>	
									<textarea  class="profile_add form-control" id="address1" readonly="readonly" name="address1" ><? echo $this->user_details->address1;?></textarea>
							<?}}else{?>
								<textarea  class="profile_add form-control" id="address1" name="address1" ></textarea>
							<?}?></div>
						</div><span style="color:red" id="erroraddress1"></span>
						<div class="form-group">
							<label class="control-label col-sm-3 ">Address 2</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['address2'])){?>
								<textarea  class="profile_add form-control" id="address2" name="address2" ><? echo $_SESSION['usersinfo']['address2'];?></textarea>
							<?}else if(isset($this->user_details->address2)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<textarea class="profile_add form-control" id="address2" name="address2" ><? echo $this->user_details->address2;?></textarea>
								<?}else{?>
									<textarea class="profile_add form-control" id="address2" name="address2"   readonly="readonly" ><? echo $this->user_details->address2;?></textarea>
							<?}}else{?>
									<textarea  class="profile_add form-control" id="address2" name="address2" ></textarea>
							<?}?></div>
						</div><span style="color:red" id="erroraddress2"></span>
						<div class="form-group ">
							<label class="control-label col-sm-3 ">Address 3</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['address3'])){?>
								<textarea  class="profile_add form-control" id="address3" name="address3"   ><? echo $_SESSION['usersinfo']['address3'];?></textarea>
							<?}else if(isset($this->user_details->address3)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<textarea  class="profile_add form-control" id="address3" name="address3" ><? echo $this->user_details->address3;?></textarea>
								<?}else{?>
									<textarea  class="profile_add form-control" id="address3" name="address3"  readonly="readonly" ><? echo $this->user_details->address3;?></textarea>
								<?}}else{?>
								<textarea  class="profile_add form-control" id="address3" name="address3" ></textarea>
							<?}?></div>
						</div><span style="color:red" id="erroraddress3"></span>
						<div class="form-group">
							<label class="control-label col-sm-3 ">Landmark Near By</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['lmnear'])){?>
									<input  type="text" id="lmnear" name="lmnear"  class="form-control"  value="<? echo $_SESSION['usersinfo']['lmnear'];?>" placeholder="Landmark Near By" />
							<?} else if(isset($this->user_details->landmarknearby)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="lmnear" name="lmnear" class="form-control" value="<? echo $this->user_details->landmarknearby;?>" placeholder="Landmark Near By" />
								<?}else{?>
									<input type="text" id="lmnear" name="lmnear"  class="form-control" readonly="readonly"  value="<? echo $this->user_details->landmarknearby;?>" placeholder="Landmark Near By" />
							<?}}else{?>
								<input  type="text" id="lmnear" name="lmnear" class="form-control" value="" placeholder="Landmark Near By" />
							<?}?></div>
						</div><span style="color:red" id="errorlmnear"></span>
						<div class="form-group">
							<label class="control-label col-sm-3 ">City</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['city'])){?>
								<input  type="text" id="city" class="form-control"  value="<? echo $_SESSION['usersinfo']['city'];?>" name="city" placeholder="Please enter city"/>
							<?}else if(isset($this->user_details->city)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="city" class="form-control" value="<? echo $this->user_details->city;?>" name="city" placeholder="Please enter city"/>
								<?}else{?>
									<input  type="text" id="city"  class="form-control" readonly="readonly" value="<? echo $this->user_details->city;?>" name="city" placeholder="Please enter city"/>
							<?}}else{?>
									<input  type="text" id="city" value="" name="city" class="form-control" placeholder="Please enter city"/>
							<?}?></div>
						</div><span style="color:red" id="errorcity"></span>
						
						<div class="form-group">
							<label class="control-label col-sm-3 ">Email</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['email'])){?>
								<input  type="text" id="email" name="email" class="form-control" value="<? echo $_SESSION['usersinfo']['email'];?>" placeholder="Email" />
							<?}else if(isset($this->user_details->email)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="email" name="email" class="form-control" value="<? echo $this->user_details->email;?>" placeholder="Email" />
								<?}else{?>
									<input  type="text" id="email" name="email" class="form-control" readonly="readonly" value="<? echo $this->user_details->email;?>" placeholder="Email" />
							<?}}else{?>
								<input  type="text" id="email" name="email" class="form-control" onblur="emailSucc()" value="" placeholder="Email" />
							<?}?></div>
						</div><span id="error" style="color:red"></span> 
						      <span id="emptyemail" style="color:red"></span> 
						     <span style="color:red" id="erroremail"></span>
						<div class="form-group">
							<label class="control-label col-sm-3 ">Phone </label>
							<div class="col-sm-9">
							<?  if(isset($_SESSION['usersinfo']['phone'])){?>
								<input  type="text" id="phone" name="phone" class="form-control" value="<? echo $_SESSION['usersinfo']['phone'];?>" placeholder="Phone" />
							<?}else if(isset($this->user_details->phone)){?>
							<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
								<input  type="text" id="phone" name="phone"  class="form-control" value="<? echo $this->user_details->phone;?>" placeholder="Phone" />
							<?}else{?>
								<input  type="text" id="phone" name="phone" class="form-control" readonly="readonly" value="<? echo $this->user_details->phone;?>" placeholder="Phone" />
							<?}}else{?>
								<input  type="text" id="phone" name="phone" class="form-control" value="" placeholder="Phone" />
							<?}?></div>						
						</div><span style="color:red" id="errorphone"></span>
						<div class="form-group">
							<label class="control-label col-sm-3 ">Fax </label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['fax'])){?>
								<input  type="text" id="fax" name="fax" class="form-control" placeholder="Fax" value="<? echo $_SESSION['usersinfo']['fax'];?>" />
							<?}else if(isset($this->user_details->fax)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="fax" name="fax" class="form-control" placeholder="Fax" value="<? echo $this->user_details->fax;?>" />
								<?}else{?>
								<input  type="text" id="fax" name="fax" class="form-control"  readonly="readonly" placeholder="Fax" value="<? echo $this->user_details->fax;?>" />
	                        <?}}else{?>
								<input  type="text" id="fax" name="fax" class="form-control" placeholder="Fax" value="" />
							<?}?></div>
						</div><span style="color:red" id="errorfax"></span>

						<input type="hidden" id="indsCntrysIds" name="indsCntrysIds" value="<? if(isset($_SESSION['usersinfo']['indsCntrysIds'])){ echo $_SESSION['usersinfo']['indsCntrysIds']; } else{ echo "";} ?><? if(isset($this->loadedCombinations) && ! isset($_SESSION['usersinfo']['indsCntrysIds'])){ echo $this->loadedCombinations; } else{ echo "";} ?>" />
						<input type="hidden" id="indsCntrysCount" name="indsCntrysCount" value="<? if(isset($_SESSION['usersinfo']['indsCntrysCount'])){ echo $_SESSION['usersinfo']['indsCntrysCount']; } else{ echo "";} ?><? if(isset($this->existingCombsCount) && ! isset($_SESSION['usersinfo']['indsCntrysCount']) ){ echo $this->existingCombsCount; } else{ echo "";} ?>" />
						<input type="hidden" id="hid_user_id" name="hid_user_id" value="<? if(isset($this->user_details->user_id)){echo $this->user_details->user_id;}?>">
						<input type="hidden" id="exit_email" name="exit_email" value="0">
						<input type="hidden" id="edit_status" name="edit_status" value="<? if(isset($_GET['edit'])){echo $_GET['edit'];}?>">						
						<div class="form-group botton_btns">
							<div class="col-sm-3">
											&nbsp;
										</div>
										<div class="col-sm-9">
											
											<a href="#" class="btn btn-danger back_btn" role="button" onclick="validate();"> 
												Continue
											</a>
										</div>
							
						</div>
				<div style="display:none;"><select id="currentIndustry"></select><select id="currentCountry"></select></div>
				</form>
		</div>
	</div>
</div>
</div>
<script type="text/javascript">

var rc = 1;
var ct = 1;

$( document ).ready(function()
{
	var indsCntrysCount = $("#indsCntrysCount").val().trim();
	var indsCntrysIds = $("#indsCntrysIds").val();
	
	// alert( indsCntrysCount );
	// alert( indsCntrysIds );
	
	$("#country1").change();
	$("#country1").change
	(
		function()
		{
			populateIndustries( $("#country1").val(),1,'later' );
		}
	);
	if( indsCntrysIds != "" )
	{
		var indsCntrysRows = indsCntrysIds.split( "!" );
		var firstCombinationIds = indsCntrysRows[0].split( "#" );
		$("#country1").val( firstCombinationIds[1].trim() );
		
		if( indsCntrysCount == 1 )
		{
			populateIndustries( $("#country1").val(),1,'initial' );
		}
	}
	
	if( indsCntrysCount > 1 )
	{
		if( $("#curAdd").length )
		{
			$("#curAdd").remove();
		}
		if( $("#curAddC") )
		{
			$("#curAddC").remove();
		}
		for( var indsCntrysOptId = 2; indsCntrysOptId <= indsCntrysCount; indsCntrysOptId++ )
		{
			$("#currentCountry").html( $("#country" + rc).html() );
			$("#currentCountry").val( $("#country" + rc).val() );
			// $("#currentCountry option:selected").remove();
			
			rc++;
			var newCountryHtml = "<div class='form-group' id='cformsList'><label class='control-label col-sm-3'>Country</label><div class='select_6'>";
			newCountryHtml += "<select name='country[]' id='currCountry' class='form-control'>" + $("#currentCountry").html();
			
			// alert( newCountryHtml );
			
			if( indsCntrysOptId == indsCntrysCount )
			{
				if( $('#currentCountry > option').length > 2 )
				{
					newCountryHtml += "</select></div>" + "&nbsp;<a id='curAddC' style='cursor:hand;cursor:pointer' Onclick='Javascript:addCountry();'><u>Add</u></a>&nbsp;&nbsp;&nbsp;<a id='curDelC' style='cursor:hand;cursor:pointer' Onclick='Javascript:delCurrCountry();'><u>Delete</u></a></div><span id='errorCtry' style='color:red';></span>";
				}
				else
				{
					newCountryHtml += "</select></div>" + "&nbsp;&nbsp;&nbsp;<a style='cursor:hand;cursor:pointer' id='curDelC' Onclick='Javascript:delCurrCountry();'><u>Delete</u></a></div><span id='errorCtry' style='color:red';></span>";
				}
			}

			// $("#indsCtrs").html( $("#industries").html() + newCountryHtml );
			$("#indsCtrs").append( newCountryHtml );
			
			$("#cformsList").attr( "id","currCFormsList" + rc );

			$("#currCountry").attr( "id","country" + rc );
			$("#errorCtry").attr( "id","errorcountry" + rc );

			// alert ( $("#country" + rc).val() );
			// alert( rc + "#" + ct );

			$("#country" + rc).change
			(
				function()
				{
					populateIndustries( this.value,this.id.replace("country", ""),'later' );
				}
			);

			ct++;
			var newIndustryHtml = "<div class='form-group' id='formsList'><label class='control-label col-sm-3'>Industry</label><div class='select_6'>";
			newIndustryHtml += "<select name='industry[]' id='currInd' class='form-control'><option value=''>-Select a industry</option></select></div></div><span id='errorInd' style='color:red';></span>";
			
			// alert( newIndustryHtml );
			
			// $("#indsCtrs").html( $("#industries").html() + newIndustryHtml );
			$("#indsCtrs").append( newIndustryHtml );
			
			$("#formsList").attr( "id","currFormsList" + ct );

			$("#currInd").attr( "id","industry" + ct );
			$("#errorInd").attr( "id","errorindustry" + ct );
			
			// alert ( $("#industry" + ct).val() );
		}
		for( var indsCntrysOptId = 2,addedCombinationId = 1; indsCntrysOptId <= indsCntrysCount; indsCntrysOptId++,addedCombinationId++ )
		{
			var addedCombinationIds = indsCntrysRows[addedCombinationId].split( "#" );
			$("#country" + indsCntrysOptId).val( addedCombinationIds[1].trim() );
		}
		for( var ajaxCallId = 1; ajaxCallId <= indsCntrysCount; ajaxCallId++ )
		{
			// alert( ajaxCallId + "#" + $("#country" + ajaxCallId).val() );
			populateIndustries( $("#country" + ajaxCallId).val(),ajaxCallId,'initial' );
		}

		// alert( ct );
	}
});


function addIndustry()
{
	// alert($("#industry" + ct));
	
	ct++;
	var newIndustryHtml = "<div class='form-group' id='formsList'><label class='control-label col-sm-3'>Industry</label><div class='select_6'>";
	newIndustryHtml += "<select name='industry[]' id='currInd' class='form-control'><option value=''>-Select a industry</option></select></div></div><span id='errorInd' style='color:red';></span>";
	
	// alert( newIndustryHtml );
	
	// $("#indsCtrs").html( $("#industries").html() + newIndustryHtml );
	$("#indsCtrs").append( newIndustryHtml );
	
	$("#formsList").attr( "id","currFormsList" + ct );

	$("#currInd").attr( "id","industry" + ct );
	$("#errorInd").attr( "id","errorindustry" + ct );

	$("#industry" + ct).val( "" );
	// alert ( $("#industry" + ct).val() );
}

// function to delete the newly added set of elements
function delCurrIndustry()
{
	$("#currFormsList" + ct).remove();
	ct--;
}

function addCountry()
{
	// alert($("#country" + rc));
	if( $("#country" + rc).val() == 0 )
	{
		alert( "Please select country" );
		return false;
	}

	if( $("#curAddC").length == 1 )
	{
		$("#curAddC").remove();
	}

	if( $("#curDelC").length == 1 )
	{
		$("#curDelC").remove();
	}
	
	$("#currentCountry").html( $("#country" + rc).html() );
	$("#currentCountry").val( $("#country" + rc).val() );
	
	/* Allowing repeat of countries */
	// $("#currentCountry option:selected").remove();
	
	rc++;
	var newCountryHtml = "<div class='form-group' id='cformsList'><label class='control-label col-sm-3'>Country</label><div class='select_6'>";
	newCountryHtml += "<select name='country[]' id='currCountry' class='form-control'>" + $("#currentCountry").html();
	
	if( $('#currentCountry > option').length > 2 )
	{
		newCountryHtml += "</select></div>" + "&nbsp;<a id='curAddC' style='cursor:hand;cursor:pointer' Onclick='Javascript:addCountry();'><u>Add</u></a>&nbsp;&nbsp;&nbsp;<a id='curDelC' style='cursor:hand;cursor:pointer' Onclick='Javascript:delCurrCountry();'><u>Delete</u></a></div><span id='errorCtry' style='color:red';></span>";
	}
	else
	{
		newCountryHtml += "</select></div>" + "&nbsp;&nbsp;&nbsp;<a style='cursor:hand;cursor:pointer' id='curDelC' Onclick='Javascript:delCurrCountry();'><u>Delete</u></a></div><span id='errorCtry' style='color:red';></span>";
	}
	
	// alert( newCountryHtml );
	
	// $("#indsCtrs").html( $("#industries").html() + newCountryHtml );
	$("#indsCtrs").append( newCountryHtml );
	
	$("#cformsList").attr( "id","currCFormsList" + rc );

	$("#currCountry").attr( "id","country" + rc );
	$("#errorCtry").attr( "id","errorcountry" + rc );

	$("#country" + rc).val( "" );
	
	$("#country" + rc).change
	(
		function()
		{
			populateIndustries( this.value,this.id.replace("country", ""),'later' );
		}
	);
	// alert ( $("#country" + rc).val() );
	
	addIndustry();
}

// function to delete the newly added set of elements
function delCurrCountry()
{
	$("#currCFormsList" + rc).remove();
	rc--;
	
	if( $("#curDelC").length == 1 )
	{
		$("#curDelC").remove();
	}
	
	// alert( $("#currCFormsList" + rc).html() );
	
	$("#currCFormsList" + rc).append( "<a style='cursor:hand;cursor:pointer' id='curAddC' Onclick='Javascript:addCountry();'><u>Add</u></a>" );
	
	if( rc > 1 )
	{
		$("#currCFormsList" + rc).append( "&nbsp;&nbsp;&nbsp;<a style='cursor:hand;cursor:pointer' id='curDelC' Onclick='Javascript:delCurrCountry();'><u>Delete</u></a>" )
	}
	
	delCurrIndustry();
}

function populateIndustries( counytId,IndustryEleId,callTime )
{
	if( (counytId == null) || (typeof counytId ==="undefined") )
	{
		// alert( "here" + counytId );
		var optionsHtmla = "<option value=''>-Select a industry</option>";
		$("#industry" + IndustryEleId).html( optionsHtmla );

		return false;
	}
	if( counytId == "" )
	{
		alert( "Please select country." );
		var optionsHtmla = "<option value=''>-Select a industry</option>";
		$("#industry" + IndustryEleId).html( optionsHtmla );

		return false;
	}
	
	// alert( $("#country" + IndustryEleId).length  );
	// alert(IndustryEleId);
	// alert(counytId);
	countrytIdArr = counytId.split( "-" );
	countrytId = countrytIdArr[0];
	
	// alert(countrytId);
	
				   
				   $.ajax({
					url:BASE_PATH+"/users/loadCountryIndustries",
					type:"POST",
					data:{countrytId:countrytId},
					success: function(data){
					// alert(data.output);
					 if(data.output=='success'){
						var industriesInfo = data.industriesInfo;
						// alert( data.industriesInfo );
						var optionsHtml = "<option value=''>-Select a industry</option>";

						var retRows = data.industriesInfo.split( "!" );
						for( var retRowId = 0; retRowId < retRows.length; retRowId++  )
						{
							var industryRow = retRows[retRowId].split( "/" );
							var industryName = industryRow[1];
							// alert( industryName );
							optionsHtml += "<option value=" + retRows[retRowId] + ">" + industryName + "</option>";
						}
						
						$("#industry" + IndustryEleId).html( optionsHtml );
						
						var indsCntrysIds = $("#indsCntrysIds").val();
						if( indsCntrysIds != "" && callTime == "initial" )
						{
							var indsCntrysRows = indsCntrysIds.split( "!" );
							for( var indsCntrysRowId = 0,elecountId=1; indsCntrysRowId < indsCntrysRows.length; indsCntrysRowId++,elecountId++  )
							{
								if( elecountId == IndustryEleId )
								{
									var currIndustryVal = indsCntrysRows[indsCntrysRowId].split( "#" );
									$("#industry" + IndustryEleId).val( currIndustryVal[0] );
								}
							}
						}
						else
						{
							$("#industry" + IndustryEleId).val( "" );
						}
						
					}else{
						}
					},
				});
				
				
	return false;
}


	function validate(){
	    var flag=true;	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var letters = /^[a-zA-Z ]*$/;
       //var valid1 = /^[0-9]+$/;        
		var validpattern = /^[+-]?\d+$/;
		//var valid3=/^[\d\s() -]+$/;
		var companyname=$('#cname').val();
		// var industry=$('#industry').val();
		var address1=$('#address1').val();
		var address2=$('#address2').val();
		var address3=$('#address3').val();
		var landmarknearby=$('#lmnear').val();
		var city=$('#city').val();
		// var country=$('#country').val();
		var emailcheck=$('#email').val();
		var pnumber=$('#phone').val();
		var fax=$('#fax').val();
		var exit_email=$("#exit_email").val();
		if(companyname==""){
			$('#errorcname').html('*Company name is required');	
			flag=false;
		}else{
			$('#errorcname').html('');
		}
		
		for( var countryId = 1; countryId <= rc; countryId++ )
		{
			if( $("#country" + countryId).val() == "" )
			{
				$("#errorcountry" + countryId).html('*Country required');
				flag=false;
			}
			else
			{
				$("#errorcountry" + countryId).html('');
			}
		}

		for( var industryId = 1; industryId <= ct; industryId++ )
		{
			if( $("#industry" + industryId).val() == "" )
			{
				$("#errorindustry" + industryId).html('*Industry is required');
				flag=false;
			}
			else
			{
				$("#errorindustry" + industryId).html('');
			}
		}

		if(address1==""){
			$('#erroraddress1').html('*Address filed is required');
			flag=false;
		}else{
			 $('#erroraddress1').html('');
		}
		if(address2==""){
			$('#erroraddress2').html('*Address filed is required');
			flag=false;
		}else{
			 $('#erroraddress2').html('');
		}
        if(address3==""){
			$('#erroraddress3').html('*Address filed is required');
			flag=false;
		}else{
			 $('#erroraddress3').html('');
		}
		if(landmarknearby==""){
			$('#errorlmnear').html('*Land mark near by is required');	
			flag=false;
		}else{
			$('#errorlmnear').html('');
		}
		if(city==""){
			$('#errorcity').html('*City is required');
			flag=false;
		}else{
			$('#errorcity').html('');
		}

		if(emailcheck==""){
		  $('#erroremail').html('*User email is required');
		  flag=false;
		}else if(!filter.test(emailcheck)){
		  $('#erroremail').html('Email format is not correct');
		  $("#error").html("");
		  flag=false;
		}else if(exit_email=='1'){
			$('#erroremail').html('');
			 $("#error").html("User is already exits");
			flag=false;
		}else{
		   $('#erroremail').html('');
		}
		if(pnumber==""){
		  $('#errorphone').html('*Phone number is required');
		  flag=false;
		}else if(!pnumber.match(validpattern)){
		     $('#errorphone').html('*Invalid phone number');
			   flag=false;
		}else{
		 $('#errorphone').html('');
		}
		if(fax==""){
			$('#errorfax').html('*Fax is required');	
			flag=false;
		}else if(isNaN(fax)){
		    $('#errorfax').html('Fax contains numbers only');
			flag=false;
		}else{
			$('#errorfax').html('');
		}

		var combinations = "";
		if( ct != rc )
		{
			if( flag )
			{
				alert( "Please select equal number of industries and countries." );
			}
			flag=false;
		}
		else
		{
			// alert( "equal." );
			combinationRepeated = false;
			
			for( var ilId = 1; ilId < ct; ilId++ )
			{
				for( var olId = ilId+1; olId <= ct; olId++ )
				{
					if( ($("#industry" + ilId).val() == $("#industry" + olId).val()) && ($("#country" + ilId).val() == $("#country" + olId).val()) )
					{
						
						combinationRepeated = true;
					}
				}
			}
			
			if(  combinationRepeated )
			{
				alert( "Combination cannot be repeated." );
				flag=false;
			}
			else
			{
				for( var elementId = 1; elementId <= ct; elementId++ )
				{
					industryId = $("#industry" + elementId).val().split( "/" );
					combinations +=  industryId[0] + "#";
					countryId = $("#country" + elementId).val().split( "-" );
					combinations +=  countryId[0] + "!";
				}
				
				combinations = combinations.substring(0, (combinations.length-1));
			}
		}
		
		// alert( combinations );
		// alert( flag );
		if(flag==false){
			return false;
		}else{
			// alert( "here" );
				   var hid_user_id = $('#hid_user_id').val();
				   $.ajax({
					url:BASE_PATH+"/users/checkadmincombinations",
					type:"POST",
					data:{combinations:combinations,hid_user_id:hid_user_id},
					success: function(data){
					// alert( "data.output" + data.output);
					 if(data.output=='success'){
							var result = data.combsStatus.substring(0, (data.combsStatus.length-1));

							var displayMsg = "";
							var retRows = result.split( "!" );
							for( var retRowId = 0; retRowId < retRows.length; retRowId++  )
							{
								var IdsStatuses = retRows[retRowId].split( "-" );
								var Idsstatus = IdsStatuses[1];
								var bothIds = IdsStatuses[0];
								var Ids = bothIds.split( "#" );

								var industryId = Ids[0];
								var countryId = Ids[1];
								// alert( industryId + " " + countryId + " " + Idsstatus );

								for( var elementId = 1; elementId <= ct; elementId++ )
								{
									indIdsText = $("#industry" + elementId).val().split( "/" );
									countIdsText = $("#country" + elementId).val().split( "-" );
									if( (indIdsText[0] == industryId) && (countIdsText[0] == countryId) )
									{
										if( Idsstatus == 1 )
										{
											displayMsg += "Combination " + countIdsText[1] + " " + indIdsText[1] + " exists.\n";
											flag=false;
										}
									}
								}
							}
							
							// alert( flag );
							if( flag==false )
							{
								alert( displayMsg );
							}
							else
							{
								// alert( flag + " can submit." );
								var sessionCombinations = "";
								
								$('#indsCntrysIds').val( combinations );
								for( var elementId = 1; elementId <= ct; elementId++ )
								{
									sessionCombinations +=  $("#industry" + elementId).val() + "#" + $("#country" + elementId).val()+ "!";
								}
								sessionCombinations = sessionCombinations.substring(0, (sessionCombinations.length-1));

								// alert( sessionCombinations );
								$('#indsCntrysCount').val( ct );
								$('#indsCntrysIds').val( sessionCombinations );
								// alert( $('#indsCntrysIds').val() );
								$("#signupForm").submit();
							}
							
							// alert( "returning." );
							// return false;
						
						}else{
						}
					},
				});
		}
	}
	function emailSucc(){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		flag=true;
		  var emailcheck=$('#email').val();
		   if(emailcheck==""){
		     $('#erroremail').html('*User email is required');
			 flag=false;
		   }else if(!filter.test(emailcheck)){
			$('#erroremail').html('Email format is not correct');
			$("#error").html("");
			flag=false;
			}
			if(flag==false){ 
				return false;
			}else{
				   $.ajax({
					url:BASE_PATH+"/users/checkregemail",
					type:"POST",
					data:{email:emailcheck},
					success: function(data){
					 if(data.output=='success'){
						$("#exit_email").val('1');
						$('#erroremail').html('');
						$("#error").html("User is already exits");			 
						}else{
							$("#exit_email").val('0');
							$("#error").html("");
							$('#erroremail').html('');
						}
					},
				});
			}
   }
</script>
<?php }else{?>
<script>
	window.location='<? echo $this->Url('home')?>';
</script>
<?php }?>
	

        